package afesocketserver;

import java.util.*;

public class GameServerGUI extends javax.swing.JFrame {
    protected GameServer server;
    protected Timer timer;

    public GameServerGUI(GameServer server) {
        initComponents();
        this.server = server;
        this.timer = new Timer();
        this.timer.schedule(new UpdateClientCountTask(this.server, this.clientCountLabel), 1000, 1000);
    }

    public void write(String msg) {
        try {
            this.debugTextArea.getDocument().insertString(0, msg + "\n", null);
        }
        catch (Exception e) {            
        }
    }

    public void writeClient(String msg) {
        try {
            this.debugClients.getDocument().insertString(0, msg + "\n", null);
        } catch (Exception e)
        {
            
        }
    }

    public void writeClientCoord(String msg) {
        try {
            this.debugClientCoords.getDocument().insertString(0, msg + "\n", null);
        } catch (Exception e)
        {
            
        }
    }

    public void clearClientLists() {
        this.debugClients.setText("");
        this.debugClientCoords.setText("");
    }

    public void clearClientCoord() {
        this.debugClientCoords.setText("");
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        clientCountLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        debugTextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        debugClients = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        debugClientCoords = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        clientCountLabel.setText("0 clients");

        debugTextArea.setColumns(20);
        debugTextArea.setEditable(false);
        debugTextArea.setRows(5);
        jScrollPane1.setViewportView(debugTextArea);

        debugClients.setColumns(20);
        debugClients.setRows(5);
        debugClients.setFocusable(false);
        jScrollPane2.setViewportView(debugClients);

        debugClientCoords.setColumns(20);
        debugClientCoords.setRows(5);
        jScrollPane3.setViewportView(debugClientCoords);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE)
                    .addComponent(clientCountLabel)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(clientCountLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel clientCountLabel;
    private javax.swing.JTextArea debugClientCoords;
    private javax.swing.JTextArea debugClients;
    private javax.swing.JTextArea debugTextArea;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    // End of variables declaration//GEN-END:variables
    
}
